$(document).ready(function() {
    $('form').submit(function(event) {
        var username = $('#username').val();
        var password = $('#password').val();
        var nickname = $('#nickname').val();
        var phone = $('#phone').val();
        var email = $('#email').val();
        var usertype = $('#user-type').val();
        
        if (!username || !password || !nickname || !phone || !email) {
            alert('所有字段都是必填的！');
            event.preventDefault();
            return;
        }

        if (password.length < 6) {
            alert('密码长度必须大于六个字符！');
            event.preventDefault();
            return;
        }

        // 添加成功提示信息
        alert('用户添加成功！');
        addUserToList(username, nickname, phone, email, usertype); // 添加用户到列表
        event.preventDefault(); // 阻止表单提交
    });
    function addUserToList(username, nickname, phone, email, usertype) {

        var userList = $('#user-list');
        var html = '<tr><td>' + username + '</td><td>' + nickname + '</td><td>' + phone + '</td><td>' + email + '</td><td>' + usertype + '</td><td><button class="btn btn-danger delete-btn">删除</button></td></tr>';
        userList.append(html);
    }
    
    $(document).on('click', '.delete-btn', function() {
        $(this).closest('tr').remove(); // 删除当前行
    });
});